﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using KeepItFreeMvc.Models;

namespace KeepItFreeMvc.Controllers
{

        public class PlaceController : ApiController
        {
            private KeepItFreeMvc.Models.KeepItFreeEntities1 repository = new KeepItFreeMvc.Models.KeepItFreeEntities1();

            public IEnumerable<Place> GetAllPlaces()
            {
                return repository.Place.ToList();
            }

            public Place GetPlaceById(int id)
            {
                var place = repository.Place.FirstOrDefault((p) => p.Id == id);
                if (place == null)
                {
                    //var resp = new HttpResponseMessage(HttpStatusCode.NotFound);
                    //throw new HttpResponseException(resp);
                }
                return place;
            }

            public IEnumerable<Place> GetPlaceByName(string name)
            {
                return repository.Place.ToList().Where(
                    (p) => string.Equals(p.Name, name, StringComparison.OrdinalIgnoreCase));
            }
        }

}
